import request_sl from '@/utils/request_sl';

export const downloadFile = (row) => {
  return request_sl({
    url: `/sl/api/db-backup/file/download?id=${row.id}&fileName=${row.fileName}`,
    method: 'get',
    responseType: 'blob',
  });
};

export const deleteFile = (row) => {
  return request_sl({
    url: `/sl/api/db-backup/file?id=${row.id}&fileName=${row.fileName}`,
    method: 'delete',
  });
};

export const fileCount = (id, maxFileNum) => {
  return request_sl({
    url: `/sl/api/db-backup/database/max-file-num?id=${id}&maxFileNum=${maxFileNum}`,
    method: 'post',
  });
};
export const getFileList = (id) => {
  return request_sl({
    url: `/sl/api/db-backup/file/${id}`,
    method: 'get',
    loading: true,
  });
};
export const getDbList = (params) => {
  return request_sl({
    url: '/sl/api/db-backup/database',
    method: 'get',
    loading: true,
    params,
  });
};

export const backup = (id) => {
  return request_sl({
    url: `/sl/api/db-backup/backup/${id}`,
    method: 'post',
  });
};

export const restore = (form) => {
  return request_sl({
    url: '/sl/api/db-backup/restore',
    method: 'post',
    data: form,
  });
};

export const getDatabase = (id) => {
  return request_sl({
    url: `/sl/api/db-backup/database/${id}`,
    method: 'get',
  });
};
export const addDatabase = (form) => {
  return request_sl({
    url: '/sl/api/db-backup/database',
    method: 'post',
    data: form,
  });
};
export const updateDatabase = (form) => {};
export const deleteDatabase = (id) => {
  return request_sl({
    url: '/sl/api/db-backup/database',
    method: 'delete',
    data: [id],
  });
};

export const getTask = (id) => {
  return request_sl({
    url: `/sl/api/db-backup/task/${id}`,
    method: 'GET',
  });
};

export const addTask = (form) => {
  return request_sl({
    url: '/sl/api/db-backup/task',
    method: 'POST',
    data: form,
  });
};

export const deleteTask = (id) => {
  return request_sl({
    url: '/sl/api/db-backup/task',
    method: 'DELETE',
    data: [id],
  });
};

export const getDbListByType = (dbType) => {
  return request_sl({
    url: `/sl/api/db-backup/database/selection?dbType=${dbType}`,
    method: 'GET',
  });
};
// 获取表中树结构数据
export const getTreeData = (params) => {
  return request_sl({
    url: '/sl/api/device/type/getTree',
    method: 'POST',
    loading: true,
  });
};
// 获取分页数据
export const getTableData = (params) => {
  return request_sl({
    url: '/sl/api/equipment/getDeviceByPage',
    method: 'POST',
    loading: true,
    data: params,
  });
};
// 新增数据
export const createData = (params) => {
  return request_sl({
    url: '/sl/api/equipment/intallDevice',
    method: 'POST',
    loading: true,
    data: params,
  });
};
export const updateData = (params) => {
  return request_sl({
    url: '/sl/api/equipment/updatDevice',
    method: 'POST',
    loading: true,
    data: params,
  });
};
// 删除
export const deleteData = (id) => {
  return request_sl({
    url: `/sl/api/equipment/deleteDeviceById?id=` + id,
    method: 'GET',
  });
};
